import puppeteer from 'puppeteer-core';

import GoLogin from '../src/gologin.js';
import { getCurrentProfileBookmarks } from '../src/bookmarks/utils.js';
import { updateProfileBookmarks } from '../src/browser/browser-api.js';

const { connect } = puppeteer;
(async () => {
  const GL = new GoLogin({
    token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2MjhjYTJkNDQ2NDc4ZDZkMzE2Njc0NWUiLCJ0eXBlIjoiZGV2Iiwiand0aWQiOiI2MjhjYTNkYWY3ZjExMTcxMTZjZGRlNDYifQ.dGK_cQSjS1DO1AvK433tpviT6AkpYfd2tjnU4zVKERI',
    // token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2MjhjYTJkNDQ2NDc4ZDZkMzE2Njc0NWUiLCJ0eXBlIjoiZGV2Iiwiand0aWQiOiI2MjhjYTNkYWY3ZjExMTcxMTZjZGRlNDYifQ.dGK_cQSjS1DO1AvK433tpviT6AkpYfd2tjnU4zVKERI',
  });

  let hosts = ['node-us-25.astroproxy.com:10450', 'node-us-28.astroproxy.com:10426', 'node-us-17.astroproxy.com:10490', 'node-us-60.astroproxy.com:10482', 'node-us-74.astroproxy.com:10600'];

  async function add(name0) {
    // the following parameters are required for profile creation
    var bookmark = '';
    let strings = hosts[(name0 - 1) % 5].split(':');
    let host = strings[0];
    let port = strings[1];

    const profile_id = await GL.create({
      name: 'USAALO' + name0,
      os: 'win', // 'win', 'lin', 'android'
      startUrl: 'https://account.google.com',
      // isM1: true, // for Mac M1
      navigator: {
        language: 'en-US,en;q=0.9',
        userAgent: 'random', // get random user agent for selected os
        resolution: '1024x768',
      },
      // proxy: {
      //   // mode: 'none',
      //   mode: 'socks5',
      //   host: host,
      //   port: port,
      //   username: 'easyzaki3750',0
      //   password: '37d10c',
      // },
      proxy: {
        mode: 'socks5',
        host: 'd52a6363e107abf2.as.pyproxy.io',
        port: '16666',
        username: 'A1111-zone-isp-region-us-session-' + name0 + '62367f04e-sessTime-720',
        password: 'A1111A1111',
      },
    });
    console.log(profile_id);
    // const profile = await GL.getProfile(profile_id);
    // profile.bookmarks
    // await GL.update({
    //   id: profile_id,
    //   name: 'profile_mac2',
    // });
    //
    // const profile = await GL.getProfile(profile_id);
    // console.log('new profile name=', profile.name);

    // await GL.delete(profile_id);

  }

  for (let i = 1; i < 26; i++) {
    await add(i);
  }

  // let promise = await GL.profiles(1);
  // // console.log(promise);
  //
  // for (const promiseElement of promise.profiles) {
  //   console.log(promiseElement.name + ' ' + promiseElement.id);
  // }
})();




